package org.yunmai.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.yunmai.entity.SysPermission;
import org.yunmai.vo.SysPermissionVO;

import java.util.List;

/**
* @author Administrator
* @description 针对表【sys_permission】的数据库操作Mapper
* @createDate 2025-06-03 19:47:51
* @Entity org.yunmai.entity.SysPermission
*/
@Mapper
public interface SysPermissionMapper extends BaseMapper<SysPermission> {

    @Select({
            "<script>",
            "SELECT ",
            "   p.id, ",
            "   p.title, ",
            "   p.url, ",
            "   p.level, ",
            "   p.icon, ",
            "   p.parent_id, ",
            "   parent.title AS parent_title ",
            "FROM sys_permission p ",
            "LEFT JOIN sys_permission parent ON p.parent_id = parent.id ",
            "WHERE 1=1 ",
            "<if test='keyword != null and keyword != \"\"'>",
            "   AND (p.title LIKE CONCAT('%', #{keyword}, '%') ",
            "   OR p.url LIKE CONCAT('%', #{keyword}, '%') ",
            "   OR parent.title LIKE CONCAT('%', #{keyword}, '%')) ",
            "</if>",
            "ORDER BY p.parent_id, p.level, p.id ",
            "LIMIT #{offset}, #{pageSize}",
            "</script>"
    })
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "title", column = "title"),
            @Result(property = "url", column = "url"),
            @Result(property = "level", column = "level"),
            @Result(property = "icon", column = "icon"),
            @Result(property = "parentId", column = "parent_id"),
            @Result(property = "parentTitle", column = "parent_title")
    })

    List<SysPermissionVO> selectPermissionPage(@Param("offset") int offset, @Param("pageSize") int pageSize, @Param("keyword") String keyword);
}




